﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>

</body>
<script>
    var cook = {
        "ele": (function () {
            var ele = document.createElement("table");
            ele.style.border = "solid";
            ele.style.borderWidth = "1px";
            ele.style.borderColor = "black";
            document.body.appendChild(ele);
            return ele;
        })(),
        "addItem": function (p_name) {

        },
        "getCookieValue": function (p_name) {
            var strCookie = document.cookie;
            //将多cookie切割为多个名/值对 
            var arrCookie = strCookie.split("; ");
            var userId;
            //遍历cookie数组，处理每个cookie对 
            for (var i = 0; i < arrCookie.length; i++) {
                var arr = arrCookie[i].split("=");
                //找到名称为userId的cookie，并返回它的值 
                if (p_name == arr[0]) {
                    return arr[1];
                }
            }
        },
        "display": function (p_name, p_value) {
            var t_TR = document.getElementById(p_name);
            if (t_TR != undefined && t_TR.parentNode === cook.ele) {
                t_TR.childNodes[1].innerHTML = p_value;
            } else {
                t_TR = document.createElement("tr");
                t_TR.innerHTML = "<td>" + p_name + "</td><td style='color:#00f;'>&nbsp;&nbsp; " + p_value.substring(0,Math.min(20,p_value.length)) + "</td>";
                cook.ele.appendChild(t_TR);
            }
        },
        "remove": function (p_name) {
            var t_TR = document.getElementById(p_name);
            if (t_TR != undefined && t_TR.parentNode === cook.ele) {
                cook.ele.removeChild(t_TR);
            }
        },
        "refresh": function () {
            while (cook.ele.childNodes.length > 0) {
                cook.ele.removeChild(cook.ele.childNodes[0]);
            }
            var strCookie = document.cookie;
            //将多cookie切割为多个名/值对 
            var arrCookie = strCookie.split("; ");
            var userId;
            //遍历cookie数组，处理每个cookie对 
            for (var i = 0; i < arrCookie.length; i++) {
                var arr = arrCookie[i].split("=");
                cook.display(arr[0], arr[1]);
            }
        }
    };
setInterval(cook.refresh, 1000);
</script>
</html>
